/**
 **************************************************************************************************************************
 * Class in charge of updating transform components
 **************************************************************************************************************************
 * @file RBTransformSystem.h
 **************************************************************************************************************************/


#ifndef __RBTRANSFORMSYSTEM_H__
#define __RBTRANSFORMSYSTEM_H__

#ifdef  HEADER_ONCE
#pragma HEADER_ONCE
#endif

#ifdef  HEADER_MSG
#pragma HEADER_MSG(RBTransformSystem.h)
#endif


/**************************************************************************************************************************
 * Includes
 **************************************************************************************************************************/
#include "Foundation/Platform/Types.h"
#include "RBMain/RBCommon.h"
#include "RBMain/RBSingleton.h"
#include "RBMain/RBMatrix.h"
#include <xmmintrin.h>

/**************************************************************************************************************************
 * Forward declarations
 **************************************************************************************************************************/
RBDeclareHandle(RBTransformComponent);

struct __declspec(align(16)) RBAlignedMatrix
{
    __m128 Col[4];
};

/**************************************************************************************************************************
 * Classes
 **************************************************************************************************************************/
class RBTransformSystem : public RBSingleton<RBTransformSystem>
{
public:
                                RBTransformSystem   (uint16 uiComponentCount = 500);
                               ~RBTransformSystem   ();

    RBTransformComponentHandle  NewComponent        ();

    void                        Update              ();

    void                        SetWorldMatrix      (const float4x4& matrix, RBTransformComponentHandle h);
    void                        GetWorldMatrix      (float4x4& matrix, RBTransformComponentHandle h);

private:
    void                        UpdateMatrices      (uint16 uiStart, uint16 uiCount);

private:

    RBTransformComponent*       m_aComponents;

    RBAlignedMatrix*            m_aLocalMatrices;
    RBAlignedMatrix*            m_aWorldMatrices;
    uint16*                     m_aParents;
    uint16                      m_uiMatrixCount;
    uint16                      m_uiCurrentMatrix;

};

/**************************************************************************************************************************/

#endif // __RBTRANSFORMSYSTEM_H__